package com.course.web.view;

import com.course.util.DateUtils;
import com.course.web.component.custom.LearnStatGrid;
import com.course.web.page.AdminUI;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.spring.annotation.SpringView;
import com.vaadin.ui.CustomComponent;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by Justin on 2017/7/1.
 */
@SpringView(name = LearnStatView.NAME, ui = AdminUI.class)
public class LearnStatView extends CustomComponent implements View {
    public static final String NAME = "learn-stat";

    private final LearnStatGrid statGrid;

    @Autowired
    public LearnStatView(LearnStatGrid statGrid) {
        this.statGrid = statGrid;
        setCompositionRoot(statGrid);
        setSizeFull();
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {
        String parameters = event.getParameters();
        int courseId = NumberUtils.toInt(parameters);
        statGrid.enter(courseId, DateUtils.toLocalDate(DateUtils.now()));
    }
}
